<?php
//require_once 'BaseController.php';

/**
 * 友の会用・応募フォーム
 *
 * @package apamanshop
 * @author H.Imamura
 * @copyright (c) 2013 SystemSoft Corp. All rights reserved
 */
class Inquiry_TomonokaiController extends Apm_Controller_Base
{
	/** ベースURL **/
	protected $_baseurl    = null;
	protected $_aplbaseurl = null;
	protected $_sslurl     = null;

	/** テンプレート **/
	protected $_display_path   = null;
	protected $_main_helper    = null;

	/** 共通パラメータ **/
	protected $title       = null;
	protected $description = null;
	protected $keywords    = null;
	protected $block_title = null;
	protected $block_read  = null;

	/**
	 * 初期処理
	 */
	public function preDispatch()
	{
		// ベースURL設定
		$this->_baseurl      = $this->_config['apm']['baseurl'];
		$this->_aplbaseurl   = $this->_config['apm']['apl']['static']['baseurl'];
		$this->_sslurl       = $this->_config['apm']['ssl']['baseurl'];
		
		$this->_display_path = APPLICATION_PATH . '/modules/inquiry/views/scripts/tomonokai.tpl';
		
		// ヘルパー設定
		
		// パラメータ取得
		$this->_params = $this->getParameters();
	}

	/**
	 * 後処理
	 */
	public function postDispatch()
	{
		// 共通パラメータ設定
		$this->setSubParams();
		
		//ブロック設定
		$this->_data['main'] = $this->_main_helper->getBlock($this->_data);
		
		//表示
		$this->display($this->_display_path);
	}

	/**
	 * 15週連続キャンペーン（入力フォーム）
	 *
	 */
	public function anniversary15Action()
	{
		// メインテンプレート
		$this->_main_helper = $this->getApmHelper(APPLICATION_PATH . '/modules/inquiry/views/helpers/tomonokai/anniversary15_entry.tpl');
		// 共通パラメータ取得
		$this->anniversary15getSubParams();
		// JS設定
		$this->addMetaJs('/campaign/15anniversary/shared/js/jquery.js');
		$mobile_js = '<script language="JavaScript">' . "\r\n"
		 . '<!--' . "\r\n"
		 . '$(document).bind("mobileinit", function(){' . "\r\n"
		 . '$.mobile.ajaxEnabled = false;' . "\r\n"
		 . '$.mobile.pushStateEnabled = false;' . "\r\n"
		 . '$.mobile.ajaxLinksEnabled = false;' . "\r\n"
		 . '$.mobile.ajaxFormsEnabled = false;' . "\r\n"
		 . '$.mobile.hashListeningEnabled = false;' . "\r\n"
		 . '});' . "\r\n"
		 . '//-->' . "\r\n"
		 . '</script>';
		$this->addMeta('', $mobile_js);
		$this->addMetaJs('/campaign/15anniversary/shared/js/jquery.mobile-1.1.0.min.js');
		$this->addMetaJs('/campaign/15anniversary/shared/js/jquery.validate.js');
		$this->addMetaJs('/campaign/15anniversary/shared/js/messages_ja.js');
		
		$this->title = 'アパマン友の会[15週連続キャンペーン]';
		$this->block_title .= ' 応募フォーム';
		
		// 画面設定
		if (isset($this->_params['error']) && $this->_params['error'] === '1') {
			$mySession = new Zend_Session_Namespace('tomo15Anni');
			if (isset($mySession->request_email) && !empty($mySession->request_email)) {
				$this->_params['request_email'] = $mySession->request_email;
			}
			Zend_Session::namespaceUnset('tomo15Anni');
		}
		
		// 値セット
		$this->_data = $this->_params;
	}

	/**
	 * 15週連続キャンペーン（送信完了）
	 *
	 */
	public function anniversary15sendAction()
	{
		// 共通パラメータ取得
		$this->anniversary15getSubParams();
		$this->addMeta('', '<meta name="robots" content="noindex">');
		
		// 画面設定
		if ($this->_params['result'] == '1') {
			$this->title = 'アパマン友の会[15週連続キャンペーン応募完了]';
			$this->_main_helper = $this->getApmHelper(APPLICATION_PATH . '/modules/inquiry/views/helpers/tomonokai/anniversary15_send.tpl');
			$this->block_title .= ' 応募完了';
			$this->_breadcrumb->add('応募完了');
		} else {
			$this->title = 'アパマン友の会[15週連続キャンペーン応募エラー]';
			$this->_main_helper = $this->getApmHelper(APPLICATION_PATH . '/modules/inquiry/views/helpers/tomonokai/anniversary15_senderror.tpl');
			$this->block_title .= ' 応募エラー';
			$this->_breadcrumb->add('応募エラー');
		}
		
		// 値セット
		$this->_data = $this->_params;
	}

	/**
	 * 共通パラメータ取得
	 *
	 */
	private function anniversary15getSubParams()
	{
		// Metaタグ設定
		//$this->addMeta('', '<meta name="viewport" content="target-densitydpi=device-dpi, width=980, maximum-scale=1.0, user-scalable=yes" />');
		//$this->addMeta('', '<meta name="format-detection" content="telephone=no,address=no" />');
		
		// CSS設定
		$this->addMetaCss('/campaign/15anniversary/shared/css/jquery.mobile-1.1.0.min.css', array('type' => 'text/css','media' => 'all'));
		
		// パラメータ設定
		$this->description = '';
		$this->keywords    = '';
		$this->block_title = 'すっごいサービス<br />15週連続プレゼントキャンペーン';
		$this->block_read  = '';
		
		// パンくず設定
		$this->_breadcrumb->reset();
		$this->_breadcrumb->add(Apm_Config_Search::BREADCRUMB_TOP, $this->_baseurl);									// TOP
		$this->_breadcrumb->add('すっごいサービス 15週連続キャンペーン', $this->_baseurl . 'campaign/1312_anniversary/application.html');	// キャンペーンLP
		$this->_breadcrumb->add('アパマン友の会 キャンペーン応募', $this->_sslurl . 'inquiry/tomonokai/anniversary15/');	// 応募フォーム
	}

	/**
	 * 共通パラメータ設定
	 *
	 */
	private function setSubParams()
	{
		// ヘッダー・フッターを表示しない
		$this->setXPassThroutgh();
		
		// タイトル
		$this->setTitle($this->title);
		$this->_data['title'] = $this->title;
		
		// Discription
		$this->setDescription($this->description, false);
		$this->_data['description'] = $this->description;
		
		// Keywords
		$this->setKeywords($this->keywords);
		$this->_data['keywords'] = $this->keywords;
		
		// Meta
		$this->_data['meta'] = implode("\n", $this->getMeta());
		
		// パンくず
		$breadCrumb = $this->_breadcrumb->generateBreadcrumb();
		$breadCrumb = str_replace("<a","<li><a", $breadCrumb);
		$breadCrumb = str_replace("</a>","</a></li>", $breadCrumb);
		$this->_data['breadCrumb'] = $breadCrumb;
		
		// H1
		$this->_data['h1_title'] = $this->block_title;
		
		// アンカー
		$this->setAnchorLink2();
		$this->_data['anchorLink'] = $this->_property['anchorLink'];
		
		// URL
		$this->_data['baseurl'] = $this->_baseurl;
		$this->_data['sslurl']  = $this->_sslurl;
	}
}
?>